package com.vhans.bapi.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.db.service.IAFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件控制器
 *
 * @author vhans
 **/
@Api(tags = "文件模块")
@RestController
public class FileController extends BaseController {

    @Autowired
    private IAFileService fileService;

    /**
     * 上传文件
     *
     * @param file 文件
     * @return {@link Result<>}
     */
    @SaCheckLogin
    @ApiOperation(value = "上传文件")
    @ApiImplicitParam(name = "file", value = "图片", required = true, dataType = "MultipartFile")
    @PostMapping("/file/upload")
    public Result<?> uploadFile(@RequestParam("file") MultipartFile file) {
        fileService.uploadFile(file, "agreement");
        return Result.success();
    }

    /**
     * 上传视频
     *
     * @param video 视频
     * @return {@link Result<>}
     */
    @SaCheckLogin
    @ApiOperation(value = "上传视频")
    @ApiImplicitParam(name = "video", value = "视频", required = true, dataType = "MultipartFile")
    @PostMapping("/video/upload")
    public Result<?> uploadVideo(@RequestParam("video") MultipartFile video) {
        fileService.uploadFile(video, "agreement");
        return Result.success();
    }
}